﻿/* Write a program that replaces in a HTML document given as string all the tags <a href="…">…</a> with corresponding tags [URL=…]…/URL]. Sample HTML fragment:
<p>Please visit <a href="http://academy.telerik.com">our site</a> to choose a trainning course. Also
visit <a href="www.bgdev.org">our forum</a> to discuss the courses.</p>
 * 
 <p>Please visit [URL=http://academy.telerik.com]our site[/URL] to choose a trainning course.
Also visit [URL=www.devbg.org]our forum[/URL] to discuss the courses.</p>
 */
using System;
using System.Text.RegularExpressions;

namespace _15.ReplaceHTML
{
    class ReplaceHTML
    {
        static void Main()
        {
            Console.WriteLine("Enter a string: ");
            string str = Console.ReadLine();
            //string str = @"<p>Please visit <a href=""http://academy.telerik.com"">our site</a> to choose a trainning course. Also visit <a href=""www.bgdev.org"">our forum</a> to discuss the courses.</p>";
            Regex r = new Regex(@"<a href=""(.*?)"">", RegexOptions.IgnoreCase);
            string replaced = r.Replace(str, @"[URL=""$1""]"); //replace openning tag
            Regex r2 = new Regex(@"<\/a>", RegexOptions.IgnoreCase);
            replaced = r2.Replace(replaced, @"[/URL]"); //replace openning tag
            Console.WriteLine(replaced);
        }
    }
}
